import type { Card, CardDetail, CardListData, CardListParams, CardParams, CreateRuleParams, RuleListData, RuleListParams } from "@/types/card"
import { request } from "@/utils/reuqest"

/**
 * 获取月卡列表
 * @param { page, pageSize} params
 * @returns
 */
export const getCardListAPI = (params: CardListParams) => {
  return request<CardListData>('/parking/card/list', 'GET', params)
}

/**
 * 新增月卡
 * @param params 
 * @returns 
 */
export const createCardAPI = (params: Partial<CardParams>) => {
  return request('/parking/card', 'POST', params)
}

/**
 * 获取月卡详情
 * @data
 * @returns
 */
export const  getCardDetailAPI = (id: string) => {
  return request<CardDetail>(`/parking/card/detail/${id}`, 'GET')
}

/**
 * 编辑月卡
 * @param {*} data
 * @returns
 */
export const updateCardAPI = (data: Partial<CardDetail>) => {
  return request('/parking/card/edit', 'PUT', data)
}

/**
 * 删除月卡
 * @param ids 月卡id集合
 * @returns 
 */
export const delCardAPI = (ids: number[]) => {
  // 批量删除时，id用逗号隔开，通过 join 方法拼接字符串
  return request(`/parking/card/${ids.join(',')}`, 'DELETE')
}

/**
 * 查看月卡
 * @param id 月卡id
 */
export const viewCardAPI = (id: string) => {
  return request<Card>(`/parking/card/${id}`, 'GET')
}

/**
 * 续费月卡
 * @param data
 */
export const renewCardAPI = (data: Partial<CardDetail>) => {
  return request('/parking/card/recharge', 'POST', data)
}

/**
 * 获取规则列表
 * @param { page, pageSize } params
 * @returns
 */
export const getRuleListAPI = (params: RuleListParams) => {
  return request<RuleListData>('/parking/rule/list', 'GET', params)
}

// 删除计费规则
export const delRuleAPI = (id: number) => {
  // 批量删除时，id用逗号隔开，通过 join 方法拼接字符串
  return request(`/parking/rule/${id}`, 'DELETE')
}

/**
 * 新增规则
 * @param params 
 * @returns 
 */
export const createRuleAPI = (params: Partial<CreateRuleParams>) => {
  return request('/parking/rule', 'POST', params)
}

/**
 * 查看规则详情
 */
export const getRuleDetailAPI = (id: number) => {
  return request<CreateRuleParams>(`/parking/rule/${id}`, 'GET')
}

/**
 * 编辑规则
 * @param params 
 * @returns 
 */
export const updateRuleAPI = (params: Partial<CreateRuleParams>) => {
  return request('/parking/rule', 'PUT', params)
}